package com.gitee.srurl.core.util.redis;

import com.gitee.srurl.core.util.SpringContextUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;

/**
 * @author zxw
 * @date 2023/4/29 19:53
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public abstract class RedisHashUtil<T> {
    private static final RedissonClient redissonClient = SpringContextUtil.getBean(RedissonClient.class);
    public static <T> T get(String key, String field) {

        RMap<String, T> map = redissonClient.getMap(key);
        return map.get(field);
    }

    public static <T> T remove(String key, String field) {

        RMap<String, T> map = redissonClient.getMap(key);
        return map.remove(field);
    }

    public static <T> T add(String key, String field, T value) {

        RMap<String, T> map = redissonClient.getMap(key);
        return map.put(field, value);
    }

    public static <T> int size(String key) {

        RMap<String, T> map = redissonClient.getMap(key);
        return map.size();
    }
}

